from fastapi import Depends, APIRouter
from fastapi.security import OAuth2PasswordRequestForm
from mapper import user_mapper
from models.dto.register_dto import RegisterDTO

router = APIRouter()


@router.post("/token",
             summary="用户登录并获取 Token",
             description="该接口用于用户登录，并返回一个包含访问令牌的 JSON 响应。",
             tags=["授权管理"],
             response_model=dict)
def login(form_data: OAuth2PasswordRequestForm = Depends()):
    return user_mapper.login(form_data)


@router.post("/register",
             summary="注册新用户",
             description="该接口允许新用户注册，需要提供用户名、密码。",
             tags=["用户管理"],
             response_model=dict)
def register(user: RegisterDTO):
    return user_mapper.register(user)
